#include "mantouchthread.h"


ManTouchThread::ManTouchThread(Guy *m_guy,QList<SmallEnemy*> emy,QList<FollowSmallEnemy*> fsmEmy,QList<BigEnemy*>bgEmy,QList<OldGuy*>ols)
{
    OldGuyList = ols;
    SmallEnemySetList = emy;
    FollowEnemySetList = fsmEmy;
    BigEnemySetList = bgEmy;

    guy = m_guy;
}

void ManTouchThread::SendOldGuy(QList<OldGuy *>ols)
{
    OldGuyList = ols;
}

void ManTouchThread::run()
{
    for(int i=0;i<SmallEnemySetList.length();i++){
        if(!SmallEnemySetList[i]->isVisible()) continue;
        if(SmallEnemySetList[i]->collidesWithItem(guy)){
            guy->isdeath = 1;

            //qDebug("碰撞2");
        }
        for(int j=0;j<OldGuyList.length()-1;j++){
            if(SmallEnemySetList[i]->collidesWithItem(OldGuyList[j])&&OldGuyList[j]->isdeath==0&&OldGuyList[j]->isVisible()){
                OldGuyList[j]->isdeath = 1;
                qDebug("碰撞oldguy");
            }
        }
    }
    for(int i=0;i<FollowEnemySetList.length();i++){
        if(!FollowEnemySetList[i]->isVisible()) continue;
        if(FollowEnemySetList[i]->collidesWithItem(guy)){
            guy->isdeath = 1;
            //qDebug("碰撞");
        }
        for(int j=0;j<OldGuyList.length()-1;j++){
            if(SmallEnemySetList[i]->collidesWithItem(OldGuyList[j])&&OldGuyList[j]->isdeath==0&&OldGuyList[j]->isVisible())
               OldGuyList[j]->isdeath = 1;
        }
    }
    for(int i=0;i<BigEnemySetList.length();i++){
        if(!BigEnemySetList[i]->isVisible()) continue;
        if(BigEnemySetList[i]->collidesWithItem(guy)){
            guy->isdeath = 1;
            //qDebug("碰撞");
        }
        for(int j=0;j<OldGuyList.length()-1;j++){
            if(SmallEnemySetList[i]->collidesWithItem(OldGuyList[j])&&OldGuyList[j]->isdeath==0&&OldGuyList[j]->isVisible())
               OldGuyList[j]->isdeath = 1;
        }
    }
}
